package com.sh.personnel.mapper;

import com.sh.personnel.vo.dto.PasswordDto;
import com.sh.personnel.vo.dto.UserInfoDto;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

/**
 * @author 林思浩
 * @date 2020/03/14 1:08
 */
@Repository
public interface UserInfoMapper {

    //获取用户个人头像
    @Select("SELECT avatar FROM tb_user WHERE id = #{id}")
    String findUserAvatar(String id);

    //获取用户个人信息
    @Select("SELECT t1.*, t2.name AS departmentName, t3.name as positionName FROM tb_user t1" +
            " LEFT JOIN tb_department t2 ON t1.departmentid = t2.id" +
            " LEFT JOIN tb_position t3 ON t1.positionid = t3.id WHERE t1.id = #{id}")
    UserInfoDto findUserInfo(String id);

    //修改用户个人信息
    @Update("UPDATE tb_user SET phone = #{phone}, birthday = #{birthday}, gender = #{gender}," +
            " province = #{province}, city = #{city}, district = #{district}, wish = #{wish}" +
            " WHERE id = #{id}")
    int updateUserInfo(UserInfoDto userInfo);

    //修改用户个人头像
    @Update("UPDATE tb_user SET avatar = #{avatar} WHERE id = #{id}")
    int updateUserAvatar(@Param("id") String id,
                         @Param("avatar") String avatar);

    //修改邮箱
    @Update("UPDATE tb_user SET email = #{email} WHERE id = #{id}")
    int updateEmail(@Param("id") String id, @Param("email") String email);

    //修改密码
    @Update("UPDATE tb_user SET password = #{newPassword}" +
            " WHERE id = #{id}")
    int updatePassword(PasswordDto passwordDto);

    //获取用户密码
    @Select("SELECT password FROM tb_user WHERE id = #{id}")
    String findUserPasswordById(String id);
}
